<template>
  <div class="comment-item">
    <van-cell class="comment-item" v-for="item in comment" :key="item.id">
      <van-image
        slot="icon"
        class="avatar"
        round
        fit="cover"
        :src="item.avatar"
      />
      <div slot="title" class="title-wrap">
        <div class="user-name">{{item.name}}</div>
        <van-button class="like-btn"
        @click="onCommentLike "
        ><van-icon name="good-job-o" /></van-button>
      </div>

      <div slot="label">
        <p class="comment-content">{{item.value}}</p>
        <div class="bottom-info">
          <span class="comment-pubdate">{{formatDate(new Date())}}</span>
          <van-button class="reply-btn"
          round
          >回复</van-button>
        </div>
      </div>
    </van-cell>
  </div>
</template>

<script>
import { getComment } from '@/api/comment'
import { formatDate } from '@/utils/dayjs'
export default {
  name: 'CommentItem',
  data () {
    return {
      comment: []
    }
  },
  created () {
    this.getComment()
  },
  methods: {
    formatDate,
    async getComment () {
      this.comment = await getComment()
      console.log('comment', this.comment)
    },
    async onCommentLike () {
      this.$toast('点赞成功')
    }
  }
}
</script>

<style scoped lang="less">
.comment-item {
  // margin-bottom: 70px;
  .avatar {
    width: 72px;
    height: 72px;
    margin-right: 25px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 26px;
    }
  }
  .comment-content {
    font-size: 32px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 19px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
  }
  .reply-btn {
    width: 135px;
    height: 48px;
    line-height: 48px;
    font-size: 21px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }
    &.liked {
      color: #e5645f;
    }
  }
}
</style>
